<%@page import="com.tubeonfire.model.admin.PlaylistModel"%>
<%@page import="com.tubeonfire.entity.Playlist"%>
<%@page import="com.tubeonfire.entity.Mission"%>
<%@page import="com.tubeonfire.model.admin.MissionModel"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	MissionModel model = (MissionModel)request.getAttribute("result");		
	String url = (String)request.getAttribute("url");
	List<Mission> list = model.getListResult();	
	String status = (String)request.getParameter("status");
	if(status==null){
		status = "0";
	}
	String type = (String)request.getParameter("type");
	if(type==null){
		type = "0";
	}
%>
<jsp:include page="/admin/elements/header.jsp">
	<jsp:param value="Mission Manager" name="title"/>
</jsp:include>
<script type="text/javascript" src="/admin/js/mine/list_mission.js"></script>
<script type="text/javascript" src="/admin/js/custom/tables.js"></script>
<script type="text/javascript" src="/admin/js/custom/general.js"></script>
	<body class="loggedin">
		<jsp:include page="/admin/elements/top.jsp"/>
	    <!-- START OF MAIN CONTENT -->
	    <div class="mainwrapper">
	     	<div class="mainwrapperinner">  	     		       	       
				<jsp:include page="/admin/elements/left.jsp">
					<jsp:param value="mission" name="current_page"/>
				</jsp:include>					              	                   
	        	<div class="maincontent noright">
	        		<div class="maincontentinner">	
        				<ul class="maintabmenu multipletabmenu">
		                	<li class="current"><a href="/admin/mission/list">Manage Mission</a></li>
		                    <li><a href="/admin/mission/add">New Mission</a></li>		                    
		                </ul>            			               
		                     
	                	<div class="content">	
	                	<jsp:include page="/admin/elements/message.jsp"/>	
	                	<div id="messageDiv" class="notification hidden">						   
						    <p></p>
						</div>
	                		<form id="youtubeSearch" class="stdform" method="get" action="/admin/mission/list">
	                			<p>
		                        	<label>By Status</label>
		                            <select class="radius3" id="status" name="status" style="min-width: 18%">
				                    	<option value="0" <%=status.equals("0")?"selected":"" %>>All</option>		
				                    	<option value="1" <%=status.equals("1")?"selected":"" %>>Active</option>
				                    	<option value="2" <%=status.equals("2")?"selected":"" %>>Done</option>				                    	
				                    </select> &nbsp;
		                        </p>  
		                        <p>
		                        	<label>By Type</label>
		                            <select class="radius3" id="type" name="type" style="min-width: 18%">
				                    	<option value="0" <%=type.equals("0")?"selected":"" %>>All</option>
				                    	<option value="1" <%=type.equals("1")?"selected":"" %>>Follow</option>
				                    	<option value="2" <%=type.equals("2")?"selected":"" %>>Transport</option>					                    	
				                    </select> &nbsp;
		                        </p>     		                            		                         		                    	                                                                    		                                                                    		                
		                        <p class="stdformbutton">
		                        	<button class="submit radius2">Search</button>		                        	
		                        </p>
                   			</form>		                	    	                   
	                    	<div class="contenttitle">
	                    		<h2 class="image"><span>List Mission</span></h2>
	                    	</div>
	                    	<div class="tableoptions">			                	
			                    <select class="radius3 action" id="action">			  
			                    	<option value="0">Select action</option>                  	
			                    	<option value="1">Delete all checked mission</option>				                    			                    
			                    </select> &nbsp;
			                    <button class="radius3" id="applyMission">Apply</button>			                  
			                    <small class="desc" style="float: right;">(Tips)</small>		                    	
			                </div>						                          
		                    <table id="table-result" cellpadding="0" cellspacing="0" border="0" class="stdtable stdtablecb">		                    
			                    <colgroup>
			                        <col class="con0">
			                        <col class="con1">
			                        <col class="con0">
			                        <col class="con1">
			                        <col class="con0">
			                        <col class="con1">
			                        <col class="con0">			                        
			                    </colgroup>
			                    <thead>
			                        <tr>
			                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
			                            <th class="head1">Type</th>
			                            <th class="head0">Title</th>
			                            <th class="head1">Channel</th>	
			                            <th class="head0">Playlist</th>			                            
			                            <th class="head1">Status</th>
			                          	<th class="head0">Action</th>
			                        </tr>
			                    </thead>
			                    <tfoot>
			                        <tr>
			                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
			                            <th class="head1">Thumb</th>
			                            <th class="head0">Title</th>
			                            <th class="head1">Channel</th>			                            
			                            <th class="head0">Playlist</th>			                            
			                            <th class="head1">Status</th>
			                          	<th class="head0">Action</th>
			                        </tr>
			                    </tfoot>
			                    <tbody>
			                    <%
				                	if(list!=null&&list.size()>0){				               								
										for(Mission obj: list){																			
									%>
				                        <tr>
				                        	<td class="center"><span class="checkbox"><input type="checkbox" value="<%=obj.getId()%>"></span></td>
				                            <td class="center">
				                            	<%
				                            		if(obj.getType()==1){
				                            			%>
				                            				Follow
				                            			<%
				                            		}else{
				                            			%>
				                            				Transport
				                            			<%
				                            		}
				                            	%>	
				                            </td>
				                            <td><%=obj.getTitle() %></td>
				                            <td class="center">
				                            	<a href="http://www.youtube.com/user/<%=obj.getSearchKeyword() %>" title="View channel <%=obj.getSearchKeyword() %>" target="blank"><%=obj.getSearchKeyword() %></a>	
				                            </td>
				                            <td class="center">
				                            	<%
				                            		Playlist pl =  PlaylistModel.byId(obj.getPlaylistId(), true);
				                            		if(pl!=null){
				                            			%>
				                            			<a href="/admin/playlist/edit?id=<%=pl.getId()%>" title="View playlist <%=pl.getTitle() %>" target="blank"><%=pl.getTitle()%></a>		
				                            			<%				                            			
				                            		}else{
				                            			%>
				                            				<small>Not exists</small> 
				                            			<%
				                            		}
				                            	%>		
				                            	 	                            
				                            </td>					                            
				                            <td class="center" style="color: green; font-weight: bold;">				                            	
				                            	<%
				                            		if(obj.getStatus()==1){
				                            			%>
				                            			Active <%if(obj.getType()==2){%>(<%=(int) (((float) (obj.getSearchPage()-1) / (float) obj.getSearchTotalPage()) * 100) %>%)<%} %>		
				                            			<%
				                            		}else{
				                            			%>
				                            			Done
				                            			<%
				                            		}
				                            	%> 
				                            	
				                            </td>				                           
				                            <td class="center">				                            	 				                            
				                            	<a class="stdbtn <%=pl==null?"btn_red":""%> btnDelete" target="blank" href="<%=obj.getId()%>" title="Delete Mission">Delete</a> 				                            					                            
				                            </td>
				                        </tr>
			                        <%
										}	
				                	}
			                        %>			                        		                       
			                    </tbody>
			                </table>   
		                                                          
	                    	<br clear="all" />	   
	                    	<%
	                    		if(model.getTotalPage()>1){
	                    	%>  	                    	
	                    	<div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate" style="border: none">
	                    		<%
		                    		if(model.getPage()>1){
	                    				%>
	                    				<a href="<%=url%>?page=1"><span class="first paginate_button paginate_button_disabled">First</span></a>
	                    				<a href="<%=url%>?page=<%=model.getPage()-1%>"><span class="next paginate_button">Previous</span></a>
	                    				<%
	                    			}
	                    		%>
	                    		<span>
	                    		<%
		                    		int startPage = 1;
	                    			int endPage = 7;
	                    			int currentPage = model.getPage();
	                    			int totalPage = model.getTotalPage();
	                    			if(currentPage<=3){
	                    				startPage = 1;
	                    				if(totalPage >= 7){
	                    					endPage = 7;	
	                    				}else{
	                    					endPage = totalPage;
	                    				}	                    					
	                    			}else{	
	                    				startPage = currentPage - 3;
	                    				if((totalPage-currentPage)>3){
	                    					endPage = currentPage + 3;	
	                    				}else{
	                    					endPage = totalPage;
	                    					startPage = totalPage - 6;
	                    					if(startPage<=0){
	                    						startPage = 1;
	                    					}	                    					
	                    				}		                    			
	                    			}	
	                    			for(int i = startPage;i<=endPage;i++){
			                  			if(model.getPage()==i){
			                  				%>  
				                    		<span class="paginate_active"><%=i %></span>
	                    					<%
			                  			}else{
			                  				%>
			                  				<a href="<%=url%>?page=<%=i%>"><span class="paginate_button"><%=i %></span></a>
			                  				<%
			                  			}
			                  		}	                    			
	                    		%>
	                    		</span>
	                    		<%
		                    		if(model.getTotalPage()>model.getPage()){
	                    				%>
	                    				<a href="<%=url%>?page=<%=model.getPage()+1%>"><span class="next paginate_button">Next</span></a>
	                    				<a href="<%=url%>?page=<%=model.getTotalPage()%>"><span class="last paginate_button">Last</span></a>
	                    				<%
	                    			}
	                    		%>
                    		</div>               	              
	                    	<%
	                    		}		                	
	                    	%>	
	                </div>
	               
	                <!--content-->	                
	            </div><!--maincontentinner-->
				<jsp:include page="/admin/elements/bottom.jsp"></jsp:include>                    	           	
	        </div><!--maincontent-->	                        
	     	</div><!--mainwrapperinner-->
	    </div><!--mainwrapper-->
		<!-- END OF MAIN CONTENT -->   
		<div id="opacity"></div>
		<img id="image_loadder" src="/admin/images/ajax-loader.gif">     
	</body>
</html>
